package com.tencent.controller;/**
 * @Author King
 * @Date 2022/8/30 15:59
 * @Version 1.0.0
 */


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tencent.entity.Result;
import com.tencent.entity.SetMeal;
import com.tencent.mapper.SetmealMapper;
import com.tencent.service.SetmealService;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.function.Predicate;

/**
 * @program: health2.2
 *
 * @description:套餐管理
 *
 * @author: king
 *
 * @create: 2022-08-30 15:59
 **/
 @RestController
 @RequestMapping("/setmeal1")
public class SetmealController {
     @Autowired
     private SetmealService setmealService;

     @Autowired
     private SetmealMapper setmealMapper;
     //查询所有套餐
    @RequestMapping("/getAllSetmeal")
    public Result getAllSetmeal(){
//        String sex = request.getParameter("sex");
//        QueryWrapper<SetMeal> qw = new QueryWrapper<>();
//        qw.eq("sex",sex);
//        List<SetMeal> list1 = setmealMapper.selectList(qw);
//        request
        try {

//            List<SetMeal> list =  setmealService.list();
            List<SetMeal> list = setmealMapper.selectList(null);
            for (SetMeal setMeal : list) {

            }
            return Result.success(list);
//            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.noLogin("失败");
        }


    }
    @RequestMapping("/getSetmealSex")
    public Result getSetmealSex(HttpServletRequest request){
        try {
            String sex = request.getParameter("sex");
            System.out.println(sex);
            QueryWrapper<SetMeal> qw = new QueryWrapper<>();

            Predicate<String> pre = gender->!gender.equals("0");


            qw.eq(pre.test(sex),"sex",sex);

            List<SetMeal> meals = setmealMapper.selectList(qw);
            for (SetMeal meal : meals) {
                System.out.println(meal);
            }
            return Result.success(meals);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.noLogin("失败");
        }


    }
    @GetMapping("/findById")
    public Result findById(Integer id) {

        try {

           SetMeal byId = (SetMeal) setmealService.findById(id);

            return Result.success(byId);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.noLogin("失败");
        }


//        Setmeal setmeal = this.setmealService.findSetmealDetailById(id);
//        setmeal.setImg("http://rfdez533a.hb-bkt.clouddn.com/" + setmeal.getImg());
//        return new Result(true, "查询成功", setmeal);
    }
}
